package com.tmbb.hntt.service.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tmbb.hntt.dao.NeroHateDao;
import com.tmbb.hntt.dto.NeroHate;
import com.tmbb.hntt.service.NeroHateService;

/**
 * @author Shenba
 *
 */
@Service
public class NeroHateServiceImpl implements NeroHateService {
	
	private NeroHateDao neroHateDao = null;

	/* (non-Javadoc)
	 * @see com.tmbb.hntt.service.NeroHateService#getNeroHates()
	 */
	public List<NeroHate> getNeroHates() {
		return neroHateDao.getNeroHates();
	}

	/* (non-Javadoc)
	 * @see com.tmbb.hntt.service.NeroHateService#save(com.tmbb.hntt.dto.NeroHate)
	 */
	@Override
	public String save(NeroHate neroHate) {
		List<NeroHate> neroHates = neroHate.getNeroHates();
		for(NeroHate er : neroHates) {
			if(StringUtils.isEmpty(er.getCurrencyCode())) {
				neroHateDao.insertNeroHate(er);
			}
			else {
				neroHateDao.updateNeroHate(er);
			}
		}
		return null;
	}
	
	/* (non-Javadoc)
	 * @see com.tmbb.hntt.service.NeroHateService#delete(com.tmbb.hntt.dto.NeroHate)
	 */
	@Override
	public String delete(NeroHate neroHate) {
		List<NeroHate> neroHates = neroHate.getNeroHates();
		for(NeroHate er : neroHates) {
			if(er.isDeleteFlag()) {
				neroHateDao.deleteNeroHate(er.getCurrencyCode());
			}
		}
		return null;
	}
	
	/**
	 * @param NeroHateDao
	 */
	@Autowired
	public void setNeroHateDao(NeroHateDao neroHateDao) {
		this.neroHateDao = neroHateDao;
	}

}
